const fs = require('fs');
const path = require('path');

var filePath = path.join(__dirname, './folders')

function delDir(file) {
    if (fs.existsSync(file)) {
        var files = fs.readdirSync(file);
        for (var i = 0; i < files.length; i++) {
            var childPath = path.join(file, files[i]);
            var stat = fs.statSync(childPath);
            if (stat.isFile()) {
                fs.unlinkSync(childPath, (err) => {
                    if (err) {
                        console.log(err);
                    }
                });
            } else if (stat.isDirectory()) {
                delDir(childPath);
            }
        }
        fs.rmdirSync(file);
    } else {
        console.log('文件路径不存在');
    }
}
delDir(filePath)